import { ApiProperty } from '@nestjs/swagger'
import { IsString, IsOptional, MinLength, MaxLength, IsIn, IsNumber, IsBoolean, IsObject } from 'class-validator'

export class CreatePermissionDto {
  @ApiProperty({ description: '权限名称', example: 'user:create' })
  @IsString()
  @MinLength(2)
  @MaxLength(100)
  permission: string

  @ApiProperty({ description: '权限显示名', example: '创建用户' })
  @IsString()
  @MinLength(2)
  @MaxLength(50)
  label: string

  @ApiProperty({ description: '权限描述', example: '创建新用户', required: false })
  @IsOptional()
  @IsString()
  @MaxLength(200)
  description?: string

  @ApiProperty({ description: '权限类型', example: 'menu', enum: ['menu', 'button', 'api'] })
  @IsString()
  @IsIn(['menu', 'button', 'api'])
  type: string

  @ApiProperty({ description: '权限路径', example: '/users', required: false })
  @IsOptional()
  @IsString()
  @MaxLength(200)
  path?: string

  @ApiProperty({ description: '权限方法', example: 'POST', required: false })
  @IsOptional()
  @IsString()
  @IsIn(['GET', 'POST', 'PUT', 'DELETE', 'PATCH'])
  method?: string

  @ApiProperty({ description: '父级权限ID', example: '1', required: false })
  @IsOptional()
  @IsNumber()
  parentId?: number

  @ApiProperty({ description: '权限排序', example: 0, required: false })
  @IsOptional()
  @IsNumber()
  sort?: number

  @ApiProperty({ description: '权限状态', example: 1, enum: [0, 1], required: false })
  @IsOptional()
  @IsNumber()
  @IsIn([0, 1])
  status?: number

  @ApiProperty({ description: '菜单图标', example: 'user', required: false })
  @IsOptional()
  @IsString()
  icon?: string

  @ApiProperty({ description: '是否隐藏菜单', example: false, required: false })
  @IsOptional()
  @IsBoolean()
  hidden?: boolean

  @ApiProperty({ description: '前端组件路径', example: 'views/user/index', required: false })
  @IsOptional()
  @IsString()
  component?: string

  @ApiProperty({ description: '重定向路径', example: '/users/list', required: false })
  @IsOptional()
  @IsString()
  redirect?: string

  @ApiProperty({ description: '当只有一个子项时是否总是显示本层', example: true, required: false })
  @IsOptional()
  @IsBoolean()
  alwaysShow?: boolean

  @ApiProperty({ description: '元数据', example: { title: '用户管理', noCache: true }, required: false })
  @IsOptional()
  @IsObject()
  meta?: object
}
